<template>
  <!-- 放置表单 -->
  <el-form label-width="120px" :model="userInfo" :rules="rules" style="margin-left: 120px; margin-top:30px">
    <el-form-item label="姓名:" prop="username">
      <el-input v-model="userInfo.username" style="width:300px" />
    </el-form-item>
    <el-form-item label="密码:" prop="password">
      <el-input v-model="userInfo.password" style="width:300px" show-password />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="upDate">更新</el-button>
      <el-button @click="$router.back()">返回</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { getUserDetailById, saveUserDetailById } from '@/api/departments'

// 导入局部组件必须在scrip里面导入,在App里面导入
export default {
// 组件名称
  name: '',
  // 接收局部注册的组件
  components: {},
  // 组件参数接收来自父组件的数据
  props: {},
  // 组件数据
  data () {
    return {
      userId: this.$route.query.id,
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        mobile: [
          { required: true, message: '姓名不能为空!', trigger: 'blur' },
          { min: 2, max: 4, message: '名字应该是2-4位', trigger: 'blur' }
        ],
        timeOfEntry: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  async mounted () {
    const res = await getUserDetailById(this.userId)
    // console.log(res.data)
    this.userInfo = res.data
    // this.userInfo.timeOfEntry = res.data.timeOfEntry
    // console.log(res.data.staffPhoto)
  },
  methods: {
    async  upDate () {
      await saveUserDetailById(this.userId, this.userInfo)
    }
  }
}
</script>
<style lang='less' scoped>

</style>
